package com.itheima.controller;

import com.aliyun.heima.AliyunOSSOperator;
import com.itheima.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @PostMapping("/upload")
    public Result upload ( MultipartFile file ) throws Exception {
        String originalFilename = file.getOriginalFilename();
//        String uuid = UUID.randomUUID().toString();
//        originalFilename.substring(originalFilename.lastIndexOf("."));
//        String newFileName= uuid + extName;
//        file.transferTo(new File());
        String url = aliyunOSSOperator.upload(file.getBytes(), originalFilename);
        return Result.success(url);

    }
}
